<?php echo $header; ?>

<script type="text/javascript" src="view/javascript/watermark/colorbox/jquery.colorbox-min.js"></script>
<link rel="stylesheet" type="text/css" href="view/javascript/watermark/colorbox/colorbox.css" />

<link rel="stylesheet" media="screen" type="text/css" href="view/javascript/watermark/colorpicker/colorpicker.css" />
<script type="text/javascript" src="view/javascript/watermark/colorpicker/colorpicker.js"></script>                

<script type="text/javascript" src="view/javascript/watermark/uploadify/jquery.uploadify-3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="view/javascript/watermark/uploadify/uploadify.css" />

<div id="content">
<div class="breadcrumb">
  <?php foreach ($breadcrumbs as $breadcrumb) { ?>
  <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
  <?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  
<div class="box">
	<div class="heading">
		<h1><img src="view/image/module.png" alt="" />Store Watermark Settings</h1>
		<div class="buttons">
			<a onclick="$('#setting-form').submit();" class="button"><span>Save</span></a>
			<a onclick="location = '<?php echo $cancel; ?>';" class="button"><span>Cancel</span></a>
		</div>
	</div>
	<div class="content">
		<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="setting-form">
			<table class="form">
				<tr>
					<td> Enable Watermark ?</td>
					<td>
						<select name="watermark_status">
						<?php if ($watermark_status) { ?>
							<option value="1" selected="selected">Yes</option>
							<option value="0" >No</option>
						<?php } else { ?>
							<option value="1" >Yes</option>
							<option value="0" selected="selected">No</option>
						<?php } ?>
						</select>
					</td>
				</tr>
			</table>
			<table class="list">
				<thead>
					<tr>
						<td class="center">Store Name</td>
						<td class="center">Watermark Name</td>
						<td class="center">Position</td>						
					</tr>
				</thead>
				<tbody>
					<?php foreach ($stores as $store) { ?>
						<tr>
							<td class="center"><?php echo $store['name'] ; ?> </td>
							<td class="center">
								<?php if($watermarks){ ?>
									<select name="store_watermark[<?php echo $store['store_id']; ?>][watermark]">
										<?php if (isset($storeSetting[$store['store_id']]['position'])) { ?>
											<option value="0" <?php if($storeSetting[$store['store_id']]['watermark'] == "0" ) echo 'selected="selected"'; ?> > None </option>
											<?php foreach($watermarks as $watermark){ ?>
												<?php $key= $watermark['details']['wid']; ?>
												<option value="<?php echo $key; ?>" <?php if($storeSetting[$store['store_id']]['watermark'] == $key ) echo 'selected="selected"'; ?>> <?php echo $watermark['details']['watermark_name']; ?></option>
											<?php } ?>
										<?php } else { ?>
											<option value="0" > None </option>
											<?php foreach($watermarks as $watermark){ ?>
												<?php $key= $watermark['details']['wid']; ?>
												<option value="<?php echo $key; ?>"> <?php echo $watermark['details']['watermark_name']; ?></option>
											<?php } ?>
										<?php } ?>
										
									</select>
								<?php } else {?>
									No Watermark exists.
									<input type="hidden" name="store_watermark[<?php echo $store['store_id']; ?>][watermark]" value="0" />
								<?php } ?>
							</td>
							<td class="center">
								<select name="store_watermark[<?php echo $store['store_id']; ?>][position]">
									<?php if (isset($storeSetting[$store['store_id']]['position'])) { ?>
										<option value="TopLeft" 		<?php echo $storeSetting[$store['store_id']]['position'] == "TopLeft" 	? 'selected="selected"' : ''; ?>>Top Left</option>
										<option value="TopRight" 		<?php echo $storeSetting[$store['store_id']]['position'] == "TopRight" 	? 'selected="selected"' : ''; ?>>Top Right</option>
										<option value="Center" 			<?php echo $storeSetting[$store['store_id']]['position'] == "Center" 	? 'selected="selected"' : ''; ?>>Center</option>
										<option value="BottomLeft"		<?php echo $storeSetting[$store['store_id']]['position'] == "BottomLeft" 	? 'selected="selected"' : ''; ?>>Bottom Left</option>
										<option  value="BottomRight"  	<?php echo $storeSetting[$store['store_id']]['position'] == "BottomRight" 	? 'selected="selected"' : ''; ?>>Bottom Right</option>
									<?php } else { ?>
										<option value="TopLeft">Top Left</option>
										<option value="TopRight">Top Right</option>
										<option value="Center" >Center</option>
										<option value="BottomLeft">Bottom Left</option>
										<option  value="BottomRight">Bottom Right</option>
									<?php } ?>
								</select>
							</td>
						</tr>
					<?php } ?>
				</tbody>
			</table>
			<input type="hidden" name="action" value="store" />
		</form>
	</div>
</div>
		
<div class="box">
	<div class="heading">
		<h1><img src="view/image/module.png" alt="" />Watermark Management</h1>
		<div class="buttons">
			<a href="<?php echo $create;?>" class="button"><span>New Watermark</span></a>
			<a onclick="$('#watermark-form').submit();" class="button"><span>Save</span></a>
			<a onclick="location = '<?php echo $cancel; ?>';" class="button"><span>Cancel</span></a>
		</div>
	</div>
	<div class="content">
		<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="watermark-form">
			<table class="list">
				<thead>
					<tr>
						<td width="1">
							<input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);"/>
						</td>
						<td class="center">Image</td>
						<td class="center">Product Name</td>
						<td class="center">Model</td>
						<td class="right">Action</td>					
					</tr>
				</thead>
				<tbody>					
					<?php if($watermarks){ ?>
						<?php foreach($watermarks as $watermark){ ?>
						<?php $key= $watermark['details']['wid']; ?>
						<tr>
							<td style="text-align:center;">
								<input type="checkbox" name="watermark[<?php echo $key; ?>][selected]" value="1"/>
							</td>
							<td class="center" width="100px">
								<div class="image">
									<img src="<?php echo $watermark['src'];?>" id="preview_<?php echo $key; ?>" width="100px" />
								</div>
							</td>
							<td class="center"><?php echo $watermark['details']['watermark_name']; ?></td>
							<td class="center"><?php echo $watermark['type'];?></td>
							<td class="right">
								<?php foreach ($watermark['details'] as $property => $detail) { ?>
									<?php if( !is_array($detail) ) { ?>
										<input type="hidden" name="watermark[<?php echo $key; ?>][<?php echo $property; ?>]" value="<?php echo $detail; ?>"/>
									<?php } else { ?>
										<?php foreach ( $detail as $sub_property => $sub_detail) { ?>
											<input type="hidden" name="watermark[<?php echo $key; ?>][<?php echo $property; ?>][<?php echo $sub_property; ?>]" value="<?php echo $sub_detail; ?>" />
										<?php } ?>
									<?php } ?>
								<?php } ?>
								<a class="button watermark_edit" href="<?php echo $watermark['edit_url']; ?> ">Edit</a>
							</td>
						</tr>
						<?php } ?>
					<?php } else { ?>					
						<td colspan="5" class="center">No Watermarks Exist</td>
					<?php } ?>
				</tbody>
			</table>
			<input type="hidden" name="action" value="watermark" />
		</form>		
	</div>
</div>
<?php echo $footer; ?>